#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * AI Object Base Class
 *      Provides a base class implementation for the IDisposable, IClearable
 * and INamedInstance interfaces.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;

namespace Adaptive
{
	namespace Foundation
	{
		/// <summary>
		/// Provides a base class implementation for the IDisposable, IClearable
		/// and INamedInstance interfaces.
		/// </summary>
		/// <remarks>
		/// This class provides the basic fundamental innterface implementation for most
		/// AI business object class definitions.
		/// </remarks>
		public ref class AiObjectBase abstract : public IDisposable, IClearable, INamedInstance
		{
		public:
			/*--------------------------------------------------------------------------------
			 * Public Event Definitions
			 *------------------------------------------------------------------------------*/
			#pragma region Public Event Definitions
			/// <summary>
			/// Occurs when the object is being disposed.
			/// </summary>
			virtual event EventHandler^ Disposing;
			/// <summary>
			/// Occurs when the object is being cleared.
			/// </summary>
			virtual event EventHandler^ Clearing;
			/// <summary>
			/// Occurs when the name of the instance is changed.
			/// </summary>
			virtual event EventHandler^ NameChanged;
			#pragma endregion

			/*--------------------------------------------------------------------------------
			 * Public Properties
			 *------------------------------------------------------------------------------*/
			#pragma region Public Properties
			/// <summary>
			/// Gets a value indicating whether the object has been disposed.
			/// </summary>
			/// <value>
			/// <b>true</b> if the <see cref="Dispose()"/> method has already been called on the
			/// instance; otherwise, <b>false</b>.
			/// </value>
			property bool Disposed { bool get(); }
			/// <summary>
			/// Gets a value indicating whether the object has been disposed.
			/// </summary>
			/// <value>
			/// <b>true</b> if the <see cref="Clear()"/> method has already been called on the
			/// instance; otherwise, <b>false</b>.
			/// </value>
			property bool Cleared { bool get(); }
			/// <summary>
			/// Gets or sets the unique name value assigned to the instance.
			/// </summary>
			/// <value>
			/// A unique string value assigned to a specific object instance.
			/// </value>
			virtual property String^ Name { virtual String^ get(); virtual void set(String^ value); }
			#pragma endregion
 
			/*--------------------------------------------------------------------------------
	         * Public Methods / Functions
		     *------------------------------------------------------------------------------*/
			#pragma region Public Methods / Functions
			/// <summary>
			/// Disposes of the object.
			/// </summary>
			!AiObjectBase();
			/// <summary>
			/// Clears the contents of the object instance without disposing of the instance.
			/// </summary>
			virtual void Clear();
			/// <summary>
			/// Raises the <see cref="NameChanged"/> event.
			/// </summary>
			/// <param name="e">
			/// An <see cref="EventArgs"/> event arguments instance.
			/// </param>
			virtual void OnNameChanged(EventArgs^ e);
	        #pragma endregion

		protected:

			/*--------------------------------------------------------------------------------
			 * Constructor / Dispose / Destructor Methods
			 *------------------------------------------------------------------------------*/
			#pragma region Constructor / Dispose / Destructor Methods
			/// <summary>
			/// Initializes a new instance of the class.
			/// </summary>
			/// <remarks>
			/// This is the default constructor.
			/// </remarks>
			AiObjectBase();
			/// <summary>
			/// Class destructor.
			/// </summary>
			~AiObjectBase();
			#pragma endregion

			/*--------------------------------------------------------------------------------
			 * Protected Methods / Event Methods
			 *------------------------------------------------------------------------------*/
			#pragma region Protected Methods / Event Methods
			/// <summary>
			/// Raises the <see cref="Clearing"/> event.
			/// </summary>
			/// <param name="e">
			/// An <see cref="EventArgs"/> event arguments instance.
			/// </param>
			virtual void OnClearing(EventArgs^ e);
			/// <summary>
			/// Sets the current state to non-cleared.
			/// </summary>
			virtual void SetDirty();
			/// <summary>
			/// Raises the <see cref="Disposing"/> event.
			/// </summary>
			/// <param name="e">
			/// An <see cref="EventArgs"/> event arguments instance.
			/// </param>
			virtual void OnDisposing(EventArgs^ e);
			/// <summary>
			/// Converts a standard .NET Unicode string to an ASCII-based byte array.
			/// </summary>
			/// <remarks>
			/// This is intended for internal use when unicode string data is not required.
			/// </remarks>
			/// <param name="originalUnicodeString">
			/// A string to convert to a single-character ASCII byte array.
			/// </param>
			/// <returns>
			/// A byte array containing the converted data, or <b>null</b>.
			/// </returns>
			static array<Byte>^ UnicodeToAscii(String^ originalUnicodeString);
			/// <summary>
			/// Converts an ASCII byte array to a Unicode string.
			/// </summary>
			/// <remarks>
			/// This is intended for internal use when basic ASCII text data must be 
			/// converted to a standard .NET string.
			/// </remarks>
			/// <param name="originalAsciiData">
			/// An ASCII byte (aka unsigned char) array to convert to a <see cref="String"/>.
			/// </param>
			/// <returns>
			/// A string containing the data, or <b>null</b>/
			/// </returns>
			static String^		AsciiToUnicode(array<Byte>^ originalAsciiData);
			#pragma endregion

		private:
			/*--------------------------------------------------------------------------------
			 * Private Member Declarations
			 *------------------------------------------------------------------------------*/
			#pragma region Private Member Declarations
			/// <summary>
			/// Disposed flag to prevent re-entrant calls.
			/// </summary>
			bool _cleared;
			/// <summary>
			/// Disposed flag to prevent re-entrant calls.
			/// </summary>
			bool _disposed;
			/// <summary>
			/// Name value.
			/// </summary>
			String^ _name;
			#pragma endregion

		};
	}
}